var account = {
    intiLoginForm:function(){
    	var options = {
            dataType : 'json',
            beforeSerialize : function(form, options) {
                options.url = '../account/login.json';
            },
            beforeSubmit : function() {
            	if(!$('#userName').val()){
                   $.msgBox.alert({
                        title : 'Tips',
                        msg : 'User name is null,please input a value!',
                        icon : 'warning',
                        width : 400
                    });
                    return false;
                }
                if(!$('#password').val()){
                   $.msgBox.alert({
                        title : 'Tips',
                        msg : 'Password is null,please input a value!',
                        icon : 'warning',
                        width : 400
                    });
                    return false;
                }
            	
                $('#signForm').attr('action', '../account/login.json');
                return true;
            },
            success : function(data) {
                if(data.result=='success'){
                    location.href = data.redirectUrl;
                }else{
                    $.msgBox.alert({
                        title:'Tips',
                        msg:'User name or password error!',
                        icon:'warning',
                        width:330
                    });
                }
            }
        };
        
        $('#signForm').submit(function() {
            $(this).ajaxSubmit(options);
            return false;
        });
    },
    modifyPassword:function(){
    	var originalPassword = $('#originalPassword').val();
    	var newPassword = $('#newPassword').val();
    	var confirmPassword = $('#confirmPassword').val();
    	
    	if(!originalPassword){
            $.msgBox.alert({
                title:'Tips',
                msg:'Original Password is null,please input a value!',
                icon:'warning',
                width:430
            });
            return false;
    	}
    	if(!newPassword){
            $.msgBox.alert({
                title:'Tips',
                msg:'New Password is null,please input a value!',
                icon:'warning',
                width:430
            });
            return false;
    	}
    	if(!confirmPassword){
            $.msgBox.alert({
                title:'Tips',
                msg:'Confirm Password is null,please input a value!',
                icon:'warning',
                width:430
            });
            return false;
    	}
    	if(newPassword!=confirmPassword){
            $.msgBox.alert({
                title:'Tips',
                msg:'New Password must be same to Confirm Passowrd,please modify!',
                icon:'warning',
                width:530
            });
            return false;
    	}
    	$.ajax({
			type : "POST",
			url : "../account/modifyPassword.json",
			cache : false,
			dataType : "json",
			data : {
				"originalPassword" : originalPassword,
				"newPassword" : newPassword
			},
			success : function(data) {
				if (data.result == 'success') {
					$.msgBox.alert({
						title : 'Success',
						msg : 'Modify Success!',
						icon : 'warning',
						width : 250,
						yesFun : function() {
							$('#modifyPasswordForm').resetForm();
						}
					});
				} else {
					$.msgBox.alert({
						title : 'Tips',
						msg : data.tips,
						icon : 'warning',
						width : 520
					});
				}
			}
		});
    }
};